<?php

namespace app\api\controller;

use think\Log;
use Illuminate\Support\Str;
use app\api\controller\Base;


class File extends Base
{
    public function saveBack()
    {
        $post = $this->request->post();
        $file_name = $this->request->get('file_name', '');
        if ($this->request->post('action') == 'saveBack') {
            $url = $post['data']['docURL'];
            $file = \file_get_contents(config('office_url') . $url);
            if (!$file) return;
            //保存在本地
            if ($file_name && !Str::startsWith('http', $file_name)) {
                $file_dir = ROOT_PATH . 'public' . DS;
                $file && file_put_contents($file_dir . $file_name, $file);
                Log::info("文件 {$file_name} 保存成功");
            }
        }
    }
}
